 <?php
//header("Connection: Keep-Alive");
//header("Proxy-Connection: Keep-Alive");
header("Content-Type: text/html; charset=gb2312");
set_time_limit(0);
$host="47.89.43.115";
$port=8087;

 //创建一次 实现多次通信 
    $socket=socket_create(AF_INET,SOCK_STREAM,SOL_TCP)or die("cannot create socket\n");
    $conn=socket_connect($socket,$host,$port) or die("cannot connect server\n");         
    
// 模拟多个连接   
//for($i=1;$i<=1000;$i++)
//{
//               //创建一个socket
//      //socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec'=>5, 'usec'=>500000));
//      //socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR,100);
//      socket_set_option($socket, SOL_SOCKET, SO_KEEPALIVE, 10);
//
//      //if($conn){echo "client connect ok!";}
//      socket_write($socket,"hello world! i am yzw_$i  client_".$i) or die("cannot write data\n");
//     
//      $buffer=socket_read($socket,1024,PHP_BINARY_READ);
//      
//      if($buffer)
//      {
//        echo "response was:".$buffer."\n";
//      }    
//      //socket_shutdown($socket,2);
//      //flush();
//      usleep(1000);        
//   
//    
//}
    
      socket_set_option($socket, SOL_SOCKET, SO_KEEPALIVE, 10);

      //if($conn){echo "client connect ok!";}
      $test="{
                tradecode:8801,
                analyst_id:13513312160, 
                symbol:XAUUSD,
                optype:0, 
                openprice:1264.66,
                stoploss:1252.88,
                takeprofit:1265.98,
                comment:11491535475
            }&";

      socket_write($socket,$test) or die("cannot write data\n");
     
      $buffer=socket_read($socket,1024,PHP_BINARY_READ);
      
      if($buffer)
      {
        echo "response was:".$buffer."\n";
      }    
      //socket_shutdown($socket,2);
      //flush();
      usleep(1000); 

   socket_close($socket);
      

 





